<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/mall/coupon/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='yhjmc'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsryhjmc'/>" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='yhjlx'/></label>
                        <div class="layui-input-inline">
                            <select name="type" class="layui-select">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <option value="1" <c:if test="${params.type == 1}">selected</c:if>> <fmt:message key='mjj'/></option>
                                <option value="2" <c:if test="${params.type == 1}">selected</c:if>> <fmt:message key='zpj'/></option>
                            </select>
                        </div>
                    </div>


                    <!-- 需要排序的字段 -->
                    <%--<input type="hidden" class="feijin-orderby" name="orderByCreateTime" id="orderByCreateTimeParams" value="${params.orderByCreateTime}"/>--%>
                    <%--<input type="hidden" class="feijin-orderby" name="orderByStore" id="orderByStoreParams" value="${params.orderByStore}"/>--%>
                    <%--<input type="hidden" class="feijin-orderby" name="orderByPrice" id="orderByPriceParams" value="${params.orderByPrice}"/>--%>
                    <%--<input type="hidden" class="feijin-orderby" name="orderBySalesVolume" id="orderBySalesVolumeParams" value="${params.orderBySalesVolume}"/>--%>
                    <!-- 需要排序的字段 -->
                    <input type="hidden" name="status" value="${params.status}"/>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <%--<a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> 添加</a>--%>

            <%--<a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="applysPutaway"><i class="layui-icon">&#xe605;</i> 批量申请上架</a>--%>

            <%--<a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="soldouts"><i class="layui-icon">&#x1006;</i> 批量下架</a>--%>


            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li
                            <c:if test="${params.status eq 0}">class="layui-this"</c:if> >
                        <a href="${web_domain}/mall/coupon/list"
                           <c:if test="${params.status eq 0}">style="color: rgb(0, 150, 136)"</c:if> ><fmt:message key='qb'/></a>
                    </li>
                    <li <c:if test="${params.status eq 4}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/coupon/list?status=4" <c:if test="${params.status eq 4}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='dsh'/></a>
                    </li>
                    <li <c:if test="${params.status eq 2}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/coupon/list?status=2" <c:if test="${params.status eq 2}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shtg'/></a>
                    </li>
                    <li <c:if test="${params.status eq 3}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/coupon/list?status=3" <c:if test="${params.status eq 3}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shbtg'/></a>
                    </li>
                </ul>
            </div>


            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                    <th><fmt:message key='yhjmc'/></th>
                    <th><fmt:message key='yhjlx'/></th>
                    <th><fmt:message key='sysp'/></th>
                    <th><fmt:message key='mkje'/></th>
                    <th><fmt:message key='mz'/></th>
                    <th><fmt:message key='zpsp'/></th>
                    <th><fmt:message key='ffsl'/></th>
                    <th><fmt:message key='yxq'/></th>
                    <th><fmt:message key='cjsj'/></th>
                    <th><fmt:message key='zt'/></th>
                    <th><fmt:message key='sfjx'/></th>
                    <th><fmt:message key='cz'/></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                        <td>${item.name }</td>
                        <td>
                            <c:choose>
                                <c:when test="${item.type eq 1}"><fmt:message key='mjj'/></c:when>
                                <c:when test="${item.type eq 2}"><fmt:message key='zpj'/></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${item.scopeType eq 1}"><fmt:message key='qbspky'/></c:when>
                                <c:when test="${item.scopeType eq 2}"><fmt:message key='zdsp'/></c:when>
                            </c:choose>
                        </td>
                        <td><fmt:formatNumber value="${item.conditionAmount}" type="CURRENCY"/></td>
                        <td><fmt:formatNumber value="${item.denominationAmount}" type="CURRENCY"/></td>
                        <td>${item.complimentaryGoods.name}</td>
                        <td>${item.releasedQuantity}</td>

                        <td>
                            <c:choose>
                                <c:when test="${item.validityType eq 1}">
                                    ${item.validityBeginDay} - ${item.validityEndDay}
                                </c:when>
                                <c:when test="${item.validityType eq 2}"><fmt:message key='lqh'/>${item.validityDay}<fmt:message key='tnksy'/></c:when>
                            </c:choose>
                        </td>
                        <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:ss"/></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status eq 1}"><fmt:message key='dsh'/></c:when>
                                <c:when test="${item.status eq 2}"><fmt:message key='shtg'/></c:when>
                                <c:when test="${item.status eq 3}"><fmt:message key='shbtg'/></c:when>
                                <c:when test="${item.status eq 4}"><fmt:message key='shz'/></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${item.choiceStatus eq 1}"><fmt:message key='f'/></c:when>
                                <c:when test="${item.choiceStatus eq 2}"><fmt:message key='s'/></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">

                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='ck'/></a>
                                <c:if test="${item.status eq 3}">
                                    <a href="javascript:void(0);" data-checkNote="${item.note}" class="layui-btn layui-btn-normal layui-btn-xs feijin-checkNote"><fmt:message key='ckyy'/></a>
                                </c:if>
                                <c:if test="${item.status eq 4}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs layui-btn-danger feijin-process"><fmt:message key='sh'/></a>
                                </c:if>

                                <c:if test="${item.status == 2}">
                                    <c:choose>
                                        <c:when test="${item.choiceStatus eq 1}">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs layui-btn-normal feijin-choice"><fmt:message key='swjx'/></a>
                                        </c:when>
                                        <c:otherwise>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs layui-btn-danger feijin-cancelChoice"><fmt:message key='qxjx'/></a>
                                        </c:otherwise>
                                    </c:choose>
                                </c:if>

                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });

        //设置精选优惠券
        $(".feijin-choice").click(function () {
            var id = $(this).attr("data-id");

            layer.confirm('<fmt:message key='jgyhjszwjxm?'/>', {icon: 3, title: '<fmt:message key='ts'/>'}, function (index) {
                $.ajax({
                    url: '${web_domain}/mall/coupon/' + id + '/choice',
                    type: "post",
                    dataType: "json",
                    data: {
                        "_method": "put",
                        "id": id
                    },
                    success: function () {

                        layer.close(index);
                        location.reload();
                    }
                });
            });
        });

        $(".feijin-checkNote").click(function () {
            var checkNote = $(this).attr("data-checkNote");
            layui.use('layer', function () {
                layer.msg(checkNote);
            });
        });

        $(".feijin-cancelChoice").click(function () {
            var id = $(this).attr("data-id");

            layer.confirm('<fmt:message key='qxgyhjjxm?'/>', {icon: 3, title: '<fmt:message key='ts'/>'}, function (index) {
                $.ajax({
                    url: '${web_domain}/mall/coupon/' + id + '/cancelChoice',
                    type: "post",
                    dataType: "json",
                    data: {
                        "_method": "put",
                        "id": id
                    },
                    success: function () {

                        layer.close(index);
                        location.reload();
                    }
                });
            });
        });


        //查看详情
        $(".feijin-detail").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='ckxq'/>'
                , content: '${web_domain}/mall/coupon/' + id + '/detail'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='fh'/>']
            });
        });

        //审核
        $(".feijin-process").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='shyhj'/>'
                , content: '${web_domain}/mall/coupon/' + id + '/process'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

    });
</script>
</body>
</fmt:bundle>
</html>
